<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<script type="text/javascript" src="js/jquery-3.2.0.js"></script>
<script type="text/javascript">
$(function(){
	 var pageNo=1, total=1;
	 var sname="",tel="",start="",end="";
	 	
	function doQuery(){
		
		  $.get("studentsearch.do",{pageNo:pageNo,tel:tel,sname:sname,datestart:start,dateend:end},function(p){
			 total=p.totalPage;
			 
			 $("#paging #go").val(p.pageNo);
			 $("#paging #total").text(total);
			 
			 var t=$("#stuTab");
			 t.find("tr:gt(0)").remove();
			 $.each(p.datas,function(i,d){
					t.append("<tr><td>"+d.stuno+"</td><td>"+d.sname+"</td><td>"+d.sex+"</td><td>"+d.telephone+"</td><td>"+d.qq+"</td><td>"+d.wechat+"</td><td>"+d.gradeid+"</td><td>"+(d.enterdate==null?"":d.enterdate)+"</td><td>"+d.fromcity+"</td><td>"+d.birthday+"</td><td>"+d.address+"</td><td>"+d.pass+"</td><td>"+d.idcardpic+"</td><td><a href='#' class='del' stuno='"+d.stuno+"'>删除</a><a href='studentUpdate.html' class='update' stuno='"+d.stuno+"'>修改</a><a href='studentAdd.html' class='add'>增加新生</a></td></tr>");
			 });
			 }); 
		}
		doQuery();
		//查询提交
		$("#search").click(function(){
			pageNo=1;
			sname=$("input[name=sname]").val();
			tel=$("input[name=tel]").val();
			start=$("input[name=datestart]").val();
			/* end=$("input[name=dateend]").val(); */
			doQuery();
			return false;
		});
		//首页
		$("#paging a#first").click(function(){
			pageNo=1;
			doQuery();
			return false;
		});
		//前一页
		$("#paging a#prev").click(function(){
			if(pageNo<1){
				alert("已经是首页了");
				return false;
			}
			pageNo--;
			doQuery();
			return false;
		});
		$("#paging a#next").click(function(){
			if(pageNo>=total){
				alert("已经是最后一页了");
				return false;
			}
			pageNo++;
			doQuery();
			return false;
		});
		$("#paging a#last").click(function(){
			pageNo=total;
			
			doQuery();
			return false;
		});
		//go
		$("input#go").keyup(function(event){ 
			 if(event.keyCode==13)//回车
			 {
				 if(this.value==""||isNaN(this.value)){
					 return false;
				 } 
				 if($(this).val()<1||$(this).val()>total){
					// alert("没有此页1");
					 return false;
				 }
				 pageNo=$(this).val();
				 doQuery();
			 }
		 }).blur(function(){
			 if(this.value==""||isNaN(this.value)){
				 return false;
			 } 
			 if($(this).val()<1||$(this).val()>total){
				// alert("没有此页2");
				 return false;
			 }
			 pageNo=$(this).val();
			 doQuery();
		 });
		
		
		//删除
		$("#stuTab").on("click",".del",function(){
			
			var stuno=$(this).attr("stuno");//$(this).parent().parent().find("td:eq(0)").text();
			alert("del:"+stuno);
			$.get("del.do",{stuno:stuno},function(r){
				alert(r);
				if(r=="1"){
					alert("删除成功");
					return true;
				}else{
					alert("删除失败");
					return false;
				}
			});
			//$(location).attr("href","students.html");
			return false;
		});
		
		
		$("#stuTab").on("click",".update",function(){
			alert("update");
			var stuno=$(this).attr("stuno");
			window.location="studentUpdate.html?"+stuno;
			//location.search   ?45
			return false;
		});
	 });
</script>
</head>
<body>
<h2>学生信息</h2>
<p>
<form method="get" action="students.html" id="searchForm">
 <input type="search" name="sname"   placeholder="用户名"/>
 <input type="search" name="tel"  placeholder="手机号"/> 
  <input type="search" name="qq"  placeholder="QQ号"/> 
 <input type="search" name="datestart"   placeholder="入学时间起点"/>    
 <input type="submit" value="search" id="search"/>
 </form>
</p>

<table border="1" cellpadding="0" cellspacing="0" id="stuTab">
<tr>
<td>学号</td><td>姓名</td><td>性别</td><td>电话</td><td>QQ号</td><td>微信</td><td>年级编号</td>
<td>入学日期</td>
<td>来自哪里</td><td>出生日期</td><td>地址</td><td>密码</td><td>照片</td><td>操作</td>
</tr>
</table>
 <p align="center" id="paging">
 <a href="#" id="first">首页</a>

 <a href="#" id="prev">上一页</a>

 <input type="number" min="1" id="go" name="go" style="width:30px" value=""/>/<span id="total"></span>

 <a href="#" id="next">下一页</a>

 <a href="#" id="last">末页</a>
</p>
</body>
</html>